#include <stdint.h>
#include <stdfunc.h>
#include <stdio.h>
#include <multiboot.h>
#include <memory.h>
#include <text_video.h>
#include <task.h>
#include <cpuid.h>
#include <pci.h>
#include <mp_tables.h>
#include <smbios.h>
#include <acpi.h>
#include <keyboard.h>
#include <shell.h>

void kmain(struct multiboot_info * mbi, unsigned int magic, char * nasm_ver);

void kmain(struct multiboot_info * mbi, unsigned int magic, char * nasm_ver)
{
    multitasking_enabled = false;
    setup_text_video();
 
    out8(0x3f2, (uint8_t)(0x0C));  /* turn off the floppy motor */
    
    __NASM_VER__ = (char*)((uint32_t)&nasm_ver);
    
    printf(" == E/OS v%s ==\n", _SYS_VER);
    printf("compiled with GCC v%u.%u.%u on %s at %s\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__, __DATE__, __TIME__);
    
    init_memory();
    parse_multiboot_info(mbi, magic);
    setup_multitasking();
}


void kmain_task(void)
{
    multitasking_enabled = true;
    GUTS();

    parse_cpuid();
    
    printf("SYS: parsing PCI devices...\n");
    add_task((uint32_t)init_pci, "PCI task");
    printf("SYS: parsing MP tables...\n");
    add_task((uint32_t)parse_mp_tables, "MP tables task");
    printf("SYS: parsing SMBIOS tables...\n");
    add_task((uint32_t)parse_smbios, "SMBIOS tables task");
    printf("SYS: parsing ACPI tables...\n");
    add_task((uint32_t)parse_acpi, "ACPI tables task");
    printf("SYS: installing the keyboard...\n");
    add_task((uint32_t)keyboard_task, "keyboard task");
    printf("SYS: installing the TUI shell...\n");
    add_task((uint32_t)shell_task, "TUI shell task");


    kill_task(active_task_id);
}

